import { type Response } from "express";

import { VARCHAR50_PG } from "~/db.pg";
import { Gateway, getGateway } from "@/droplet-bus/core.define";

import { app_gateway } from "./core.local";

export const UserEmailGateway: Gateway = getGateway(app_gateway, "stream_user_email");
export type patchUserEmailDto = { email: VARCHAR50_PG };
export type doUserEmailLoginDto = { email: VARCHAR50_PG; code: string };

export interface UserEmailInterface {
  /** 发送邮箱验证码 */
  patchUserEmail(dto: patchUserEmailDto): Promise<null>;

  /** 通过邮箱验证码登录 */
  doUserEmailLogin(dto: doUserEmailLoginDto): Promise<{ SessionId: string }>;
}

export interface UserEmailInterfaceInServer {
  /** 发送邮箱验证码 */
  patchUserEmail(dto: patchUserEmailDto): Promise<null>;

  /** 通过邮箱验证码登录 */
  doUserEmailLogin(response: Response, dto: doUserEmailLoginDto): Promise<{ SessionId: string }>;
}
